using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DatabaseManager.UI
{
    /// <summary>
    /// This form represents a generic input dialog, which size depends on the given label text
    /// </summary>
    public partial class FInputBox : Form
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="FInputBox"/> class.
        /// </summary>
        /// <param name="text">The caption text, which describes what information the user has to type in.</param>
        /// <param name="title">The title in the windows title bar.</param>
        /// <param name="defaultValue">The default value in the text box.</param>
        public FInputBox(string text, string title, string defaultValue, bool isPasswordBox)
        {
            InitializeComponent();

            Title = title;
            Text = text;
            Value = defaultValue;
            IsPasswordBox = isPasswordBox;

            txtValue.Select();
            txtValue.SelectAll();
        }

        public FInputBox(string text, string title, string defaultValue)
            : this(text, title, defaultValue, false) { }

        /// <summary>
        /// Initializes a new instance of the <see cref="FInputBox"/> class.
        /// The displayed default value of the text box is empty.
        /// </summary>
        /// <param name="text">The caption text, which describes what information the user has to type in.</param>
        /// <param name="title">The title in the windows title bar.</param>
        public FInputBox(string text, string title)
            : this(text, title, string.Empty, false) { }

        public FInputBox(string text, string title, bool isPasswordBox)
            : this(text, title, string.Empty, isPasswordBox) { }

        /// <summary>
        /// Gets or sets the window title.
        /// </summary>
        /// <value>The window title.</value>
        public string Title
        {
            get { return base.Text; }
            set { base.Text = value; }
        }

        /// <summary>
        /// Gets or sets the caption text, which informs the user, what to type in.
        /// </summary>
        /// <value>The text.</value>
        public override string Text
        {
            get
            {
                if (lblCaption != null)
                    return lblCaption.Text;
                else
                    return "";
            }
            set
            {
                lblCaption.Text = value;
            }
        }

        /// <summary>
        /// Gets or sets the value, which is displayed in the text box.
        /// </summary>
        /// <value>The value.</value>
        public string Value
        {
            get { return txtValue.Text; }
            set { txtValue.Text = value; }
        }

        public bool IsPasswordBox
        {
            get { return txtValue.UseSystemPasswordChar; }
            set { txtValue.UseSystemPasswordChar = value; }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
            Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Close();
        }
    }
}